
clear all
set more off

foreach domain in "deport" "defund" "defund-nocredible" {
use "data/raw/`domain'-receiver-deidentified", clear 

* Drop pre-randomization attritters and flag post-randomization attriters
drop if !inlist(condition, "excuse", "noexcuse")
gen attrit = 0
replace attrit = 1 if (donation=="NA") | (q212=="NA")
lab var attrit "Respondent attritted post-randomization"

gen excuse = condition=="excuse"
lab var excuse "Excuse condition"
gen noexcuse = condition=="noexcuse"
lab var noexcuse "No excuse condition"
drop condition

* Generate demographic and control variables
gen ind = party == "Independent"
label var ind "Independent"

gen partisan = .
replace partisan = 2 if liberal == "Very conservative"
replace partisan = 1 if liberal == "Conservative"
replace partisan = 0 if liberal == "Neither liberal nor conservative"
replace partisan = -1 if liberal == "Liberal"
replace partisan = -2 if liberal == "Very liberal"
label var partisan "Partisan leaning"

destring year, replace force
gen age = 2021-year
lab var age "Age"
drop year

gen age2 = age^2
lab var age2 "Age squared"
gen hisp = hispanic=="Yes"
lab var hisp "Spanish, Hispanic, or Latino"
drop hispanic
gen male = sex == "Male"
lab var male "Male"

lab var education "Education level"

gen white = race=="Caucasian/White"
lab var white "White"
lab var race "Race"

gen believe_donated = strpos(q212, "Yes")
label var believe_donated "Believe matched respondent donated to organization"
gen bonus = strpos(donation, "Yes")
label var bonus "Authorized $1 bonus for matched respondent"

keep attrit male education hisp white race age age2 partisan openended believe_donated bonus excuse noexcuse ind

save "data/working/`domain'-receiver.dta", replace
}
